package com.scse.bms.web.admin;

import com.scse.bms.entity.RecommendDO;
import com.scse.bms.service.RecommendService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Title: RecommendController
 * @Author: 吴赠禹
 * @Date: 2021/2/22 20:29
 * @Version: 1.0
 * @Description: TODO
 */


@Slf4j
@RestController
public class RecommendController {

    @Autowired
    private RecommendService recommendService;




    /**
     * 推荐图书
     * @param recommend
     * @return
     */
    @PostMapping("/admin/recommend/on")
    @ResponseBody
    public String toRecommend(@RequestBody RecommendDO recommend) {
        log.info("[toRecommend] 管理员ID：{}，推荐的图书编号：{}" , recommend.getAdminId(), recommend.getBookId());
        boolean save = recommendService.save(recommend);
        return String.valueOf(save);
    }


    /**
     * 不推荐图书
     * @param recommend
     * @return
     */
    @PostMapping("/admin/recommend/off")
    @ResponseBody
    public String notRecommend(@RequestBody RecommendDO recommend) {
        log.info("[notRecommend] 管理员ID：{}，不推荐的图书编号：{}" , recommend.getAdminId(), recommend.getBookId());
        int result = recommendService.remove(recommend.getBookId());
        return String.valueOf(result);
    }



    // @GetMapping("/admin/{adminId}/recommend/on/{bookId}")
    // @ResponseBody
    // public String toRecommend(@PathVariable("bookId") Integer bookId, @PathVariable("adminId") Integer adminId) {
    //     log.info("[toRecommend] 管理员ID：{}，推荐图书，编号：{}" , adminId, bookId);
    //     return "推荐！";
    // }
    //
    // @GetMapping("/admin/{adminId}/recommend/off/{bookId}")
    // @ResponseBody
    // public String notRecommend(@PathVariable("bookId") Integer bookId, @PathVariable("adminId") Integer adminId) {
    //     log.info("[notRecommend] 管理员ID：{}，不推荐图书，编号：{}" , adminId, bookId);
    //     return "不推荐！";
    // }


}
